<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<%@ taglib uri="/WEB-INF/tld/sys.tld" prefix="sys" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
 <meta name="renderer" content="webkit">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>抵押信息</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>

<script type="text/javascript">
	var grid = null;
	var pageInTab = null;
    var pageInApp = {};
    var loadedTabs=[];
	$(function () {
		initGrid();//grid
        initTab();
		  $("#searchBar").ligerForm();
		    $("#searchBtn").click(function(event) {
		         var form = new liger.get("searchBar");
		         var data = form.getData();
		         for (name in data){
		            grid.setParm(name,data[name]);
		         };
		        grid.reload();
		    });
		
	});
	  function clearBtn(){
		    $("#searchBar").ligerForm();
					var form = new liger.get("searchBar");
					form.setData({
						cstNm:" ",
						paySchNo:" ",
						guarStsCd:" ",
						mtgWayCd:""
					 });
			}
	//初始化列表
	function initGrid(){
		var params = {};
		$("#grid").ligerGrid({
	    	url: '<%=path%>/project/prjprdmtg/initList.do',
	    	method : 'get',
	    	parms:params,
	        columns: [
	            { display: '客户名称', name: 'cstNm', minWidth: 60,align:'left',enabledSort:true},
	              { display: '支付表号', name: 'paySchNo', minWidth: 100,align:'left',enabledSort:true},
	            { display: '设备名称', name: 'prdNm', minWidth: 80 ,align:'left',enabledSort:true},
	            { display: '设备型号', name: 'prdMdl', minWidth: 80,align:'left',enabledSort:true}, 
	             { display: '车架号', name: 'vin', minWidth: 80,align:'left',enabledSort:true}, 	
	                  { display: '抵押状态', name: 'guarStsCdNm', minWidth: 80 ,align:'center',
	            	 render: function (rowdata, rowindex, value, column) { 
	  	            		 var stsCd = rowdata.guarStsCdNm==null?" ":rowdata.guarStsCdNm;
	  	            		var h = '';
	  	            		if(stsCd==" "){
	  	            			h+="未抵押";
	  	            			//if(rowdata.audStsCd==FlowConstant.FLOW_CHECK_STATE_PASS ){
	  	            			//添加
		  	            		  /*   h+='<a href="javascript:addPrdMtgBtn(';
		  	                        h+="'"+rowdata.dtlId+"'";
		  	                        h+=')">未抵押</a>' */
	  	            			/* }else{
	  	            				h+="未抵押";
	  	            			} */
	  	            			
	  	            		}else{
	  	            			if(rowdata.isDel==CommonConstant.C_YN_N_0){
	  	            			   h+='<a href="javascript:detailBtn(';
		  	                        h+="'"+rowdata.id+"',";
		  	                        h+="'"+rowdata.dtlId+"'";
		  	                        h+=')">'+stsCd+'</a>'
	  	            			}
	  	            			
	  	            		} 
	  	                        return h;
	  	            		},enabledSort:true},
	             { display: '抵押有效期', name: 'mtgDeadline', minWidth: 60,align:'left',
	  	            	  render: function (rowdata, rowindex, value){
		                	  var h="";
		                		  if(rowdata.isDel==CommonConstant.C_YN_N_0){
		                			 	if(rowdata.isWithoutDay==CommonConstant.C_YN_Y_1){
		                			 		h+="无限期";	
		                			 	}else{
		                			 		var dateStr = "";
		                					if(null != value&&value!=''){
		                						var date = new Date(value);
		                						dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
		                					}
		                					h+=dateStr;
		                			 	}
		                		  }
		                    return h;
		                },enabledSort:true}, 	
		                { display: '抵押方式', name: 'mtgWayCdNm', minWidth: 80,align:'left',enabledSort:true},
		              /*   { display: '审核状态', name: 'audStsCdNm', minWidth: 80,align:'left',enabledSort:true}, 	 */
	             {
	                display: '操作',
	                isSort: false,
	                width: 200,
	                align:'left',
	                render: function (rowdata, rowindex, value){
	                	  var h="";
	                	  <sys:funcAuth resCd="prjprdmtg_modify">
	                		  if(rowdata.id&&rowdata.isDel==CommonConstant.C_YN_N_0&&(rowdata.guarStsCd==ProjectConstant.CODE_GUAR_STS_NONE||rowdata.guarStsCd==ProjectConstant.CODE_GUAR_STS_RELMTG)){
	                			// 	if(rowdata.audStsCd==FlowConstant.FLOW_CHECK_STATE_PASS){
		                        h+='<a class="sq-button-hasicon" href="javascript:modifyBtn(';
		                        h+="'"+rowdata.id+"',";
		                        h+="'"+rowdata.dtlId+"'";
		                        h+=')"><i class="sqBtnIco_4"></i>修改</a>';
		                        h+='<a class="sq-button-hasicon" href="javascript:removeBtn(';
		                        h+="'"+rowdata.id+"'";
		                        h+=')"><i class="sqBtnIco_7"></i>删除</a>';
	                			// 	}
	                		  }
	                		  if(!rowdata.id){
	                            h+='<a class="sq-button-hasicon" href="javascript:addPrdMtgBtn(';
		                        h+="'"+rowdata.dtlId+"',";
		                        h+="'"+rowdata.id+"'";
		                        h+=')"><i class="sqBtnIco_3"></i>添加</a>';
	                		  }
	                		</sys:funcAuth>
	                    return h;
	                }
	            }  
	        ],
	        pageSize:10,
	        root:'rows',
	        record:'total',
	        hideLoadButton : true,
	        width: '100%',
	        height:'100%',
	        heightDiff:-2,
	        checkbox:true,
	        allowUnSelectRow: true,
            alternatingRow: true,
	        rownumbers:true,
	        enabledEdit: true,
	        usePagerOnLessPagesize: true,
	    });
		grid = liger.get("grid");
		grid.setHeight(500);
		
	}
	//格式化为人民币格式
	function renderAmt(rowdata, rowindex, value) {
        var h="￥" + FormatMoney(value)
        return h;
    }

	//格式化时间
	function renderDate(rowdata, index, value){
		var dateStr = "";
		if(null != value&&value!=''){
			var date = new Date(value);
			dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
		}
		return dateStr;
	}
	//添加抵押信息
	function addPrdMtgBtn(dtlId,id){
		var callback = function(){
			 grid.reload();
		}
		var detailFlag = false;
		var timestamp=new Date().getTime();
		Add_navTab( 'tab_prj_prd_mtg_info_add'+timestamp,'添加抵押信息','<%=path%>/project/prjprdmtg/toAddPage.do?detailFlag='+detailFlag+'&&dtlId='+dtlId,callback);
	}

	//添加抵押信息
	function addBtn(){
		var callback = function(){
			 grid.reload();
		}
		var selectedRows = grid.getSelectedRows();
		if(selectedRows.length !=1){
			$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warring"});
			return;
		}
	    var url = '<%=path%>/project/prjprdmtg/changeGuarSts.do';
		var dtlId = selectedRows[0].dtlId;
		var id = selectedRows[0].id;
		var audStsCd = selectedRows[0].audStsCd;
		var guarStsCd = selectedRows[0].guarStsCd;
		var params = {};
		params.id=id;
		params.guarStsCd=guarStsCd;
		//if(audStsCd==FlowConstant.FLOW_CHECK_STATE_PASS){
		var detailFlag = false;
		if(id){
			$.ligerDialog.confirm("确认进行抵押/解押操作吗？", function (flag) {
				if(flag==false){return false;}
		//	if(audStsCd==CommonConstant.C_AUD_NO_HAPPEN_CODE){
				  $.ajax({
			    		type: 'post',
			    		dataType:'json',
			    		data:params,
			    		url: url,
			    		success:function(msg){
			    			 if(msg.success == 1){
			    				 top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "success"});
			    			 }else{
			    				 top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
			    			 }
			    		}
			    	});
	/* 		}else if(audStsCd==CommonConstant.C_AUD_ADNWAY_CODE){
				 top.$.ligerDialog.SQalert({content: "审核中不允许修改抵押状态",SQ_type: "error"});
			}else if(audStsCd==CommonConstant.C_AUD_PASS_CODE){
				 top.$.ligerDialog.SQalert({content: "审核通过不允许修改抵押状态",SQ_type: "error"});
			} */
			});
		}else{
			var timestamp=new Date().getTime();
		Add_navTab( 'tab_prj_prd_mtg_info_add'+timestamp,'添加抵押信息','<%=path%>/project/prjprdmtg/toAddPage.do?detailFlag='+detailFlag+'&&dtlId='+dtlId,callback);
		}
		
		/* }else{
			top.$.ligerDialog.SQalert({content: "该项目立项流程未通过不允许添加抵押信息！",SQ_type: "error"});
		} */
		
	}
	
	//修改抵押信息
	function modifyBtn(id,dtlId){
		var callback = function(){
			 grid.reload();
		}
		var detailFlag = false;
		Add_navTab( 'tab_prj_prd_veh_mtg_modify'+id,'修改抵押信息','<%=path%>/project/prjprdmtg/toAddPage.do?detailFlag='+detailFlag+'&&id='+id+'&&dtlId='+dtlId,callback);
	}

	function detailBtn(id,dtlId){
		var detailFlag = true;
		Add_navTab( 'tab_prj_prd_veh_mtg_detail'+id,'抵押详情','<%=path%>/project/prjprdmtg/toViewPage.do?detailFlag='+detailFlag+'&&id='+id+'&&dtlId='+dtlId);
	}
	
	function iframeResize () {
	    if (parent.mainApp) {
	        parent.mainApp.parentTab.onResize();
	    };
	}
	//删除所选抵押信息
	function removeBtn(id){
		/* var selectedRows = grid.getSelectedRows();
		if(selectedRows.length <1){
			$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_MORE_ROW, SQ_type: "warring"});
			return;
		}
		var _ids = [];
		for ( var index in selectedRows) {
			_ids.push(selectedRows[index].id);
		} */
		var _ids = [];
		_ids.push(id);
		$.ligerDialog.confirm(LogUtils.LOG_CMM_DELETE_CONFIRM, function (flag) {
			if(flag == false)return;
			$.ajax({
				type: 'post',
				dataType:'json',
				data:{ids:JSON.stringify(_ids)},
				url: '<%=path%>/project/prjprdmtg/removeByIds.do',
				success:function(msg){
					 if(msg.success == 1){
						 grid.reload();
					 }else{
						 top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
					 }
				}
			});
		});
		
	}
    //初始化Tab页签
    function initTab(){
        pageInTab = $("#pageInTab").ligerTab({
            height: 'auto',
            contextmenu: false,
            minIframeHeight: GET_minIframeHeight(),
            onAfterSelectTabItem: function (tabid) {
                if (loadedTabs.indexOf(tabid) < 0) {
                    loadedTabs.push(tabid);
                    if (tabid != "tabA") {
                        switch (tabid) {
                            case "tabB":
                                pageInTab.setTabItemSrc(tabid, "<%=path%>/project/prjprdmtg/toWarnListPage.do");
                                break;
                        }
                    }
                }
                SetIframe_height();
            }
        });
        $.extend(true, pageInApp, {
            pageInTab: pageInTab
        });
    };
</script>

<body class="iframeBody">
	<div class="Wrapper">
        <div id="pageInTab" class="pageInTab">
            <div tabid="tabA" title="抵押管理" lselected="true">
            <div class="searchArea">
                <form id="searchBar">
                <div class="fieldset1 clearFix">
                    <div class="fieldBox col_33" id="searchCstNmId">
                        <div class="label">客户名称</div>
                        <div class="field">
                            <input name="cstNm" id="cstNm" type="text" class="ui-textbox" value="">
                        </div>
                    </div>
                     <div class="fieldBox col_33" id="searchPayNo">
                        <div class="label">支付表号</div>
                        <div class="field">
                            <input name="paySchNo" id="paySchNo" type="text" class="ui-textbox" value="">
                        </div>
                    </div>
                     <div class="fieldBox col_33" >
                      <div class="label">抵押状态</div>
                        <div class="field">
                        <select name="guarStsCd"  id="guarStsCd" >
                         <option value="  " selected="selected">--请选择--</option>
                         <c:forEach items="${guarStsCdList}" var="opt">
                          <option value="${opt.key}">${opt.value}</option>
                         </c:forEach>
                        </select>
                        </div>
                    </div>
                    <div class="fieldBox col_33" >
                      <div class="label">抵押方式</div>
                        <div class="field">
                        <select name="mtgWayCd"  id="mtgWayCd" >
                         <option value="  " selected="selected">--请选择--</option>
                         <c:forEach items="${mtgWayList}" var="wayObj">
                          <option value="${wayObj.key}">${wayObj.value}</option>
                         </c:forEach>
                        </select>
                        </div>
                    </div>
                    <div class="clearFix"></div>
                    <div class="btnsBox">
                        <span id="searchBtn"  class="sq-button sq-button-round">查询</span>
                       <span id="clearBtn" onclick="clearBtn();" class="sq-button sq-button-round">清空</span>
                      <!-- <span id="addBtn" onclick="addBtn();" class="sq-button sq-button-round"><i class="sqBtnIco_5"></i>质押/解押</span> -->
                      <!-- <span id="removeBtn" onclick="removeBtn();" class="sq-button-round"><i class="sqBtnIco_5"></i>作废</span> -->
                    </div>
                </div>
                </form>
            </div>
            <div id="grid" class="sq-grid"></div>
        </div>
        <div tabid="tabB" title="抵押预警管理" id="tabBId">
            <iframe frameborder="0" name="tabB" id="tabB" src=""></iframe>
        </div>
    </div>
</div>
</body>
</html>